/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.vienthonga.product.logic;

import com.vienthona.common.utils.ProductUtils;
import com.vienthonga.hibernate.dao.ShowProductDAO;
import com.vienthonga.hibernate.pojo.TMobilephone;
import com.vienthonga.hibernate.pojo.TProduct;
import java.io.Reader;
import java.io.StringReader;
import java.util.Iterator;
import org.jdom.Document;
import org.jdom.input.SAXBuilder;


/**
 *
 * @author DoanHa
 */
public class ShowMobilephoneDetailLogic {
    public TProduct getMobilephoneDetail(String pId)
    {
        return ShowProductDAO.getMobilephoneDetail(pId);
    }

    // lay thong tin tu bang T_Mobilephone
    public M_Detail getMDetailInfo(TProduct product)
    {
        M_Detail mobilePhoneDetail = new M_Detail();
        try
        {
            TMobilephone mobile = new TMobilephone();
            
            Iterator iter = product.getTMobilephones().iterator();
            while(iter.hasNext())
            {
                mobile = (TMobilephone)iter.next();
            }

            String xmlString = mobile.getPDetails();

//            String str= "<?xml version=\"1.0\" encoding=\"UTF-8\"?> " +
//"<ThongTin>"+
//	"<Description>HTC Desire S sở hữu màn hình 3,7 inch và là bản nâng cấp của Desire năm ngoái. Phiên bản mới sở hữu bộ khung bằng nhôm khối, trang bị vi xử lí MSM 8255 Qualcomm tốc độ 1 GHz, camera 5 MPx phía sau, mặt trước là máy ảnh 1,3 MPx</Description>"+
//	"<General>"+
//		"<Network>GSM 850 / 900 / 1800 / 1900 ; HSDPA 900 / 2100</Network>"+
//		"<Color>Black</Color>"+
//		"<Size>115 x 59.8 x 11.6 mm </Size>"+
//		"<Weight>130 g</Weight>"+
//		"<Design></Design>"+
//		"<SIM></SIM>"+
//		"<Pin>Li-Ion 1450 mAh</Pin>"+
//	"</General>"+
//	"<Display>"+
//		"<Language>Có Tiếng Việt</Language>"+
//		"<DisplayType>S-LCD cảm ứng điện dung, 16 triệu màu</DisplayType>"+
//		"<DisplaySize>480 x 800 pixels, 3.7 inches - Mặt kính Gorilla chống trầy - Công nghệ chạm đa điểm - Xoay màn hình tự động - Proximity sensor for auto turn-off - Giao diện HTC Sense - Phím điều khiển cảm ứng</DisplaySize>"+
//	"</Display>"+
//	"<Features>"+
//		"<Ring>Rung, Đa âm điệu, MP3</Ring>"+
//		"<Message>Stereo FM radio with RDS</Message>"+
//		"<ConnectionMedia>Bluetooth USB</ConnectionMedia>"+
//		"<Camera>5 MP, 2592 x 1944 pixels, autofocus, LED flash. Geo-tagging, touch-focus, image stabilization</Camera>"+
//	"</Features>"+
//        "<Storage>"+
//		"<Contact>Rất nhiều, Danh bạ hình ảnh</Contact>"+
//		"<InternalMemory>1.1 GB ROM, 768 MB RAM</InternalMemory>"+
//		"<ExternalMemory>microSD tới 32 GB - CPU : 1 GHz Scorpion processor, Adreno 205 GPU, Qualcomm MSM8255 Snapdragon</ExternalMemory>"+
//	"</Storage>"+
//        "<Others>"+
//		"<MusicDownload>-</MusicDownload>"+
//		"<Ring>có</Ring>"+
//		"<GPRS>Lên đến 114 kbp</GPRS>"+
//		"<HSCSD>-</HSCSD>"+
//		"<EDGE>có</EDGE>"+
////		"<3G>có</3G>"+
//		"<WLAN>Wi-Fi 802.11 b/g/n, DLNA, Wi-Fi hotspot</WLAN>"+
//		"<OS>Android OS, v2.3 (Gingerbread)</OS>"+
//		"<Clock>có</Clock>"+
//		"<Alarm>có</Alarm>"+
//		"<FM>có</FM>"+
//		"<Game>Tải thêm</Game>"+
//		"<Browser>HTML</Browser>"+
//		"<Java>có</Java>"+
//		"<VideoRecorder>720p@30fps</VideoRecorder>"+
//		"<VoiceRecorder>có</VoiceRecorder>"+
//		"<ListeningMusic>Music Player : MP3/AAC+/WAV/WMA. 3.5 mm jack</ListeningMusic>"+
//		"<WatchingVideo>DivX/XviD/MP4/H.263/H.264/WMV</WatchingVideo>"+
//		"<CallRecorder>-</CallRecorder>"+
//		"<ExternalSpeaker>có</ExternalSpeaker>"+
//		"<WaitingTime>Lên đến 430 giờ (2G) / Lên đến 455 giờ (3G)</WaitingTime>"+
//		"<TalkingTime>Lên đến 9 giờ 50 phút (2G) / Lên đến 7 giờ 10 phút</TalkingTime>"+
//
//	"</Others>"+
//"</ThongTin>";

            Reader in = new StringReader(xmlString);
            SAXBuilder builder = new SAXBuilder();
            Document doc = builder.build(in);

            mobilePhoneDetail.setDescription(ProductUtils.getElementValue(doc, "/ThongTin//Description"));
           
            mobilePhoneDetail.getGeneral().setNetwork(ProductUtils.getElementValue(doc, "/ThongTin//General/Network"));
            mobilePhoneDetail.getGeneral().setColor(ProductUtils.getElementValue(doc, "/ThongTin//General/Color"));
            mobilePhoneDetail.getGeneral().setSize(ProductUtils.getElementValue(doc, "/ThongTin//General/Size"));
            mobilePhoneDetail.getGeneral().setWeight(ProductUtils.getElementValue(doc, "/ThongTin//General/Weight"));
            mobilePhoneDetail.getGeneral().setDesign(ProductUtils.getElementValue(doc, "/ThongTin//General/Design"));
            mobilePhoneDetail.getGeneral().setSim(ProductUtils.getElementValue(doc, "/ThongTin//General/SIM"));
            mobilePhoneDetail.getGeneral().setPin(ProductUtils.getElementValue(doc, "/ThongTin//General/Pin"));

            mobilePhoneDetail.getDisplay().setLanguage(ProductUtils.getElementValue(doc, "/ThongTin//Display/Language"));
            mobilePhoneDetail.getDisplay().setDisplayType(ProductUtils.getElementValue(doc, "/ThongTin//Display/DisplayType"));
            mobilePhoneDetail.getDisplay().setDisplaySize(ProductUtils.getElementValue(doc, "/ThongTin//Display/DisplaySize"));

            mobilePhoneDetail.getFeatures().setRing(ProductUtils.getElementValue(doc, "/ThongTin//Features/Ring"));
            mobilePhoneDetail.getFeatures().setMessage(ProductUtils.getElementValue(doc, "/ThongTin//Features/Message"));
            mobilePhoneDetail.getFeatures().setConnectionMedia(ProductUtils.getElementValue(doc, "/ThongTin//Features/ConnectionMedia"));
            mobilePhoneDetail.getFeatures().setCamera(ProductUtils.getElementValue(doc, "/ThongTin//Features/Camera"));

            mobilePhoneDetail.getStorage().setContact(ProductUtils.getElementValue(doc, "/ThongTin//Storage/Contact"));
            mobilePhoneDetail.getStorage().setInternalMemory(ProductUtils.getElementValue(doc, "/ThongTin//Storage/InternalMemory"));
            mobilePhoneDetail.getStorage().setExternalMemory(ProductUtils.getElementValue(doc, "/ThongTin//Storage/ExternalMemory"));

            mobilePhoneDetail.getOrthers().setMusicDownload(ProductUtils.getElementValue(doc, "/ThongTin//Others/MusicDownload"));
            mobilePhoneDetail.getOrthers().setRing_2(ProductUtils.getElementValue(doc, "/ThongTin//Others/Ring"));
            mobilePhoneDetail.getOrthers().setGprs(ProductUtils.getElementValue(doc, "/ThongTin//Others/GPRS"));
            mobilePhoneDetail.getOrthers().setHscsd(ProductUtils.getElementValue(doc, "/ThongTin//Others/HSCSD"));
            mobilePhoneDetail.getOrthers().setEdge(ProductUtils.getElementValue(doc, "/ThongTin//Others/EDGE"));
            mobilePhoneDetail.getOrthers().setNetwork_3g(ProductUtils.getElementValue(doc, "/ThongTin//Others/Network_3g"));
            mobilePhoneDetail.getOrthers().setWlan(ProductUtils.getElementValue(doc, "/ThongTin//Others/WLAN"));
            mobilePhoneDetail.getOrthers().setOs(ProductUtils.getElementValue(doc, "/ThongTin//Others/OS"));
            mobilePhoneDetail.getOrthers().setClock(ProductUtils.getElementValue(doc, "/ThongTin//Others/Clock"));
            mobilePhoneDetail.getOrthers().setAlarm(ProductUtils.getElementValue(doc, "/ThongTin//Others/Alarm"));
            mobilePhoneDetail.getOrthers().setFm(ProductUtils.getElementValue(doc, "/ThongTin//Others/FM"));
            mobilePhoneDetail.getOrthers().setGame(ProductUtils.getElementValue(doc, "/ThongTin//Others/Game"));
            mobilePhoneDetail.getOrthers().setBrowser(ProductUtils.getElementValue(doc, "/ThongTin//Others/Browser"));
            mobilePhoneDetail.getOrthers().setJava(ProductUtils.getElementValue(doc, "/ThongTin//Others/Java"));
            mobilePhoneDetail.getOrthers().setVideoRecorder(ProductUtils.getElementValue(doc, "/ThongTin//Others/VideoRecorder"));
            mobilePhoneDetail.getOrthers().setVoiceRecorder(ProductUtils.getElementValue(doc, "/ThongTin//Others/VoiceRecorder"));
            mobilePhoneDetail.getOrthers().setListeningMusic(ProductUtils.getElementValue(doc, "/ThongTin//Others/ListeningMusic"));
            mobilePhoneDetail.getOrthers().setWatchingVideo(ProductUtils.getElementValue(doc, "/ThongTin//Others/WatchingVideo"));
            mobilePhoneDetail.getOrthers().setCallRecorder(ProductUtils.getElementValue(doc, "/ThongTin//Others/CallRecorder"));
            mobilePhoneDetail.getOrthers().setExternalSpeaker(ProductUtils.getElementValue(doc, "/ThongTin//Others/ExternalSpeaker"));
            mobilePhoneDetail.getOrthers().setWaitingTime(ProductUtils.getElementValue(doc, "/ThongTin//Others/WaitingTime"));
            mobilePhoneDetail.getOrthers().setTalkingTime(ProductUtils.getElementValue(doc, "/ThongTin//Others/TalkingTime"));

            return mobilePhoneDetail;
        }
        catch(Exception ex)
        {
            System.out.println(ex.getMessage());
            return null;
        }

    }
}
